package com.atguigu.tingshu.order.adapter.Impl;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.common.rabbit.service.RabbitService;
import com.atguigu.tingshu.order.adapter.PayWay;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 微信支付逻辑
 */
@Service
public class WxPayWayImpl implements PayWay {

    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    private RabbitService rabbitService;
    @Override
    public boolean isSupport(String payWay) {
        return "1101".equals(payWay);
    }

    @Override
    public void dealPayWay(OrderInfoVo orderInfoVo, Long userId, String orderNo) {
        //微信支付逻辑
        //1.保存订单相关信息
        orderInfoService.saveOrderInfo(orderInfoVo,userId,orderNo);

        //2.延时(10min)关单 给rabbitmq的延时交换机发送一条消息
//        rabbitService.sendDealyMessage(MqConst.EXCHANGE_CANCEL_ORDER,MqConst.ROUTING_CANCEL_ORDER,orderNo,60);
        rabbitService.sendDealyMessage(MqConst.EXCHANGE_CANCEL_ORDER,MqConst.ROUTING_CANCEL_ORDER,orderNo,60 * 10);
    }
}
